package com.zzc.emotisenseclassroom.domain.user.service.impl;

import com.zzc.emotisenseclassroom.dbservice.user.UserDbService;
import com.zzc.emotisenseclassroom.domain.user.dto.GetStudentIdAndNameReqDTO;
import com.zzc.emotisenseclassroom.domain.user.service.StudentService;
import com.zzc.emotisenseclassroom.domain.user.vo.StudentIdAndNameVO;
import com.zzc.emotisenseclassroom.dto.user.StudentDTO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * Copyright Zzc
 * FileName: StudentServiceImpl
 * Author:   Zzc
 * Date:     2024/4/281:41
 * Description:学生业务层实现类
 * hISTORY:
 * <author>  <time>     <version>    <desc>
 * 作者姓名   修改时间       版本号       描述
 * Zzc                   1.0.0
 */
@Service
public class StudentServiceImpl implements StudentService {
    private static final Logger LOG = LogManager.getLogger(StudentServiceImpl.class);

    @Autowired
    private UserDbService userDbService;

    @Override
    public List<StudentDTO> getStudentListBySchoolAndClass(Map<String, Object> param) {
        try {
            Long schoolId = Long.parseLong(param.get("schoolId").toString());
            Long classId = Long.parseLong(param.get("classId").toString());
            Integer pageNum = (Integer) param.get("pageNum");
            Integer pageSize = (Integer) param.get("pageSize");
            return userDbService.getStudentListBySchoolAndClass(schoolId, classId, pageNum, pageSize);
        }catch (NullPointerException e){
            LOG.error("空指针异常", e);
            return Collections.emptyList();
        }
    }

    @Override
    public List<StudentDTO> getStudentListByCondition(Map<String, Object> param) {
        try {
            return userDbService.getStudentListByCondition(param);
        }catch (NullPointerException e){
            LOG.error("空指针异常", e);
            return Collections.emptyList();
        }
    }

    @Override
    public int countStudent(Long schoolId, Long classId) {
        return userDbService.countStudent(schoolId, classId);
    }

    @Override
    public int conditionCountStudent(Map<String, String> requestData) {
        return userDbService.conditionCountStudent(requestData);
    }

    @Override
    public List<StudentIdAndNameVO> getStudentIdAndNameList(GetStudentIdAndNameReqDTO reqDTO) {
        return userDbService.getStudentIdAndNameList(reqDTO);
    }
}
